package com.example.imageview_;

import android.app.Activity;
import android.net.sip.SipAudioCall.Listener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnCheckedChangeListener{
	private ToggleButton tb;
	private ImageButton img;
	
		
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tb = (ToggleButton) findViewById(R.id.toggleButton1);
        img = (ImageButton) findViewById(R.id.imageView1);
        /*
         * 监听事件的写入，对tb添加监听事件
         *
         */
        tb.setOnCheckedChangeListener(this);
        
    }



	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		//点击时更改tb的状态
		tb.setChecked(isChecked);
		
		// cheched 代表是否呗选中
		// 为图片进行替换
		img.setBackgroundResource(isChecked?R.drawable.ic_launcher:R.drawable.ic_launcher
				);
	}
}
